package com.school.graduation.goods.presenter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.school.graduation.R;
import com.school.graduation.goods.model.HotMarketItem;

import java.util.List;

public class HotMarketAdapter extends RecyclerView.Adapter<HotMarketViewHolder> {

    private List<HotMarketItem> hotMarketItems;
    private HotMarketItemClickListener listener;

    public HotMarketAdapter(HotMarketItemClickListener listener,List<HotMarketItem> hotMarketItems) {
        this.hotMarketItems = hotMarketItems;
        this.listener = listener;
    }

    @Override
    public HotMarketViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new HotMarketViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_hot_market, parent, false));
    }

    @Override
    public void onBindViewHolder(HotMarketViewHolder holder, int position) {
        TextView title = holder.getView(R.id.hot_item_title);
        TextView content = holder.getView(R.id.hot_item_content);
        final ImageView img = holder.getView(R.id.hot_item_img);
        RelativeLayout item = holder.getView(R.id.hot_item);
        title.setText(hotMarketItems.get(position).getTitle());
        content.setText(hotMarketItems.get(position).getContent());
        img.setImageResource(hotMarketItems.get(position).getResource());
        item.setOnClickListener(new HotItemClickListener(position));
    }

    @Override
    public int getItemCount() {
        return hotMarketItems.size();
    }

    class HotItemClickListener implements View.OnClickListener {

        private int position;

        public HotItemClickListener(int position) {
            this.position = position;
        }

        @Override
        public void onClick(View v) {
            switch (position){
                case 0:
                    listener.clickFirstHotItem();
                    break;
                case 1:
                    listener.clickSecondHotItem();
                    break;
                case 2:
                    listener.clickThirdHotItem();
                    break;
                case 3:
                    listener.clickFourthHotItem();
                    break;
                case 4:
                    listener.clickFifthHotItem();
                    break;
                case 5:
                    listener.clickSixthHotItem();
                    break;
            }
        }
    }
}
